package com.quectel.sdk.simulation;

import com.quectel.sdk.ex.hikisc.HikFactoryErrorException;

/**
 * 模拟平台实例建造器
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-19 11:01:00
 */
public class SimulationClientBuilder {


    /**
     * 模拟平台地址
     */
    private String url;
    /**
     * appKey访问凭证
     */
    private String accessKey;
    /**
     * secretKey访问凭证
     */
    private String accessSecret;

    private SimulationClientBuilder() {
    }

    public static SimulationClientBuilder builder() {
        return new SimulationClientBuilder();
    }

    public SimulationClientBuilder url(String url) {
        this.url = url;
        return this;
    }

    public SimulationClientBuilder accessKey(String accessKey) {
        this.accessKey = accessKey;
        return this;
    }

    public SimulationClientBuilder accessSecret(String accessSecret) {
        this.accessSecret = accessSecret;
        return this;
    }

    public <T extends SimulationBaseClient> T build(Class<T> executorCls) {
        if (url == null || accessKey == null || accessSecret == null) {
            throw new HikFactoryErrorException("Missing request parameter.");
        }
        try {
            T t = executorCls.newInstance();
            t.setRequester(SimulationRequester.getInstance(url, accessKey, accessSecret));
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
